老师,这个相册案例感觉还有一个bug

来源:7-2 揭秘案例bug值解决第三个bug

Qua

2019-10-29 15:12:53

就是鼠标移入中间的某一个a元素之后,显示了一张对应照片,然后再按左右键,显示的照片不是基于当前这个照片的下一张,而是会从头开始下一张。


写回答

2回答

好帮手慕慕子

2019-10-29

同学你好, 老师将你的粘贴的这部分代码,结合源码的HTML和CSS测试, 出现同学的说的这种情况, 是因为同学在鼠标移入a的时候, 没有设置index值, 也没有调用swiper方法, 建议修改:

http://img.mukewang.com/climg/5db819020997310414040411.jpg

这一点老师在课程中有讲解哦, 建议:同学可以在回顾一下课程,加深自己的理解

如果帮助到了你, 欢迎采纳!

祝学习愉快~~~

0

好帮手慕慕子

2019-10-29

同学你好,老师测试源码没有出现同学说的这种情况, 建议:同学可以清除浏览器缓存在测试一下哦

如果是测试你自己写的代码, 可以将你写的完整代码直接粘贴过来, 便于老师帮助同学准确高效的定位与解决问题

如果帮助到了你, 欢迎采纳!

祝学习愉快~~~~

0
hua
h var swiper = function() { // $('img').eq(index).stop().animate({ 'opacity': 1 }, 500).siblings().stop().animate({ 'opacity': 0 }, 500); $('img').eq(index).stop().fadeIn(500).siblings().stop().fadeOut(500); $('a').eq(index).css({ 'color': 'red' }).siblings().css({ 'color': '#255d7e' }); } $(document).on('mouseenter', 'a', function() { // $('img').eq($(this).index()).stop().animate({ 'opacity': 1 }, 500).siblings().stop().animate({ 'opacity': 0 }, 500); $('img').eq($(this).index()).stop().fadeIn(500).siblings().stop().fadeOut(500); $('a').eq($(this).index()).css({ 'color': 'red' }).siblings().css({ 'color': '#255d7e' }); }); var index = 0; $(document).on('keyup', function() { if (event.keyCode == 37) { index--; if (index < 0) { index = $('img').length - 1; } swiper(); } if (event.keyCode == 39) { index++; if (index == $('img').length) { index = 0; } swiper(); } console.log(index); }); var start = function() { index = 0; swiper(); } start(); JS的代码如上,麻烦您看下吧
h019-10-29
共1条回复

0 学习 · 14456 问题

查看课程