1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <body> <div id="container"> <ul id="content"> <li><a href="#"><img src="https://img2.baidu.com/it/u=2927586094,212838758&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=500" /></a> </li> <li><a href="#"><img src="https://img2.baidu.com/it/u=712694738,3554631191&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=353" /></a>3 </li> <li><a href="#"><img src="https://img2.baidu.com/it/u=2318304628,3725588736&fm=253&fmt=auto&app=120&f=JPEG?w=787&h=500" /></a>4 </li> <li><a href="#"><img src="https://img2.baidu.com/it/u=1686691636,3058220847&fm=253&fmt=auto&app=120&f=JPEG?w=889&h=500" /></a>6 </li> <li><a href="#"><img src="https://img0.baidu.com/it/u=3325784342,2976910751&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=281" /></a>5 </li> <li><a href="#"><img src="https://img2.baidu.com/it/u=377961337,1258578817&fm=253&fmt=auto&app=120&f=JPEG?w=1422&h=800" /></a>5 </li> <li><a href="#"><img src="https://img2.baidu.com/it/u=4260665178,1669850930&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500" /></a>4 </li> </ul> </div> </body> </body> <style> * { margin: 0; padding: 0; }
img { border: 0; }
#container { width: 800px; height: 130px; border: 3px solid blue; overflow: hidden; position: relative; }
#container ul { list-style: none; width: 10000px; position: absolute; }
#container ul li { width: 120px; height: 130px; float: left; margin-right: 10px;
}
img { width: 120px; height: 130px; } </style> <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script> <script>
window.onload = function () {
var segmentWidth = 0; var speed = 20000; $("#container #content li").each(function () { segmentWidth += $(this).outerWidth(true); });
$("#container #content li").clone().appendTo($("#container #content"));
run(speed);
function run(interval) { $("#container #content").animate({ "left": -segmentWidth }, interval, "linear", function () { $("#container #content").css("left", 0); run(speed); }); }
$("#container").mouseenter(function () { $("#container #content").stop(); }).mouseleave(function () { var passedCourse = -parseInt($("#container #content").css("left")); var time = speed * (1 - passedCourse / segmentWidth); run(time); }); };
</script>
</script>
</html>
|