1
我使用JavaScript制作了一个图像滑块,在YouTube的帮助下,当图像发生变化时,它们不会相互褪色,而是出现“跳跃”,这可以在这里显示:JavaScript图像滑块在图像之间没有淡入淡出
http://www.jdlloyd.co.uk/demo.html
有人能解释/让他们淡出人们彼此更新的代码?
感谢
CODE:
// This simple function returns object reference for elements by ID
function _(x){
\t "use strict";
\t return document.getElementById(x);}
// Variables for bubble array, bubble index, and the setInterval() variable
var ba, bi=0, intrvl;
// bca - Bubble Content Array. Put your content here.
var bca = [
'<a href="#"><img src="http://46.4.95.138/sfimages20150708/SF.US.42303038394f4e51504b.1.jpg" width=100% height="250px"></a>',
\t '<a href="#"><img src="http://img.psdvault.com/2008/12/3-copy-paste-resize-500x250.jpg" width=100% height="250px"></a>',
\t '<a href="#"><img src="http://thesixthirty.com/music/wp-content/uploads/2015/03/TheSixThirty_SongOfTheDay_Rectangle_031715.jpg" width=100% height="250px"</a>'
];
// This function is triggered by the bubbleSlide() function below
function bubbles(bi){
\t // Fade-out the content
\t "use strict";
\t _("bubblecontent").style.opacity = 0;
\t // Loop over the bubbles and change all of their background color
\t for(var i=0; i < ba.length; i++){
\t \t ba[i].style.background = "rgba(0,0,0,.1)";
\t }
\t // Change the target bubble background to be darker than the rest
\t ba[bi].style.background = "#999";
\t // Stall the bubble and content changing for just 300ms
\t setTimeout(function(){
\t \t // Change the content
\t \t _("bubblecontent").innerHTML = bca[bi];
\t \t // Fade-in the content
\t \t _("bubblecontent").style.opacity = 1;
\t }, 0);
}
// This function is set to run every 5 seconds(5000ms)
function bubbleSlide(){
\t "use strict";
\t bi++; // Increment the bubble index number
\t // If bubble index number is equal to the amount of total bubbles
\t if(bi === ba.length){
\t \t bi = 0; // Reset the bubble index to 0 so it loops back at the beginning
\t }
\t // Make the bubbles() function above run
\t bubbles(bi);
}
// Start the application up when document is ready
window.addEventListener("load", function(){
\t // Get the bubbles array
\t "use strict";
\t ba = _("bubbles").children;
\t // Set the interval timing for the slideshow speed
\t intrvl = setInterval(bubbleSlide, 5000);
});
/* BUBBLE FILTER */
#bubblebox{ width:100%; position:relative; height:250px; margin:0px; border:1px solid #000000; transition:opacity 0.3s linear 0s; border:0px; background-color:#000000;}
#bubbles{ width:100%; position: absolute; bottom: 0px; margin-left: 0px auto; margin-right: 0px auto; text-align:center; border:0px;}
#bubbles > div{ display:inline-block; width:10px; height:10px; margin:10px 10px 10px 10px; background:rgba(0,0,0,.1); text-align:center; border:2px solid #999; border-radius:100%; font-size:17px; text-decoration:none; transition: background 0.3s linear 0s; cursor:pointer; }
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Demo</title>
<link rel="stylesheet" href="style.css">
\t <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
\t <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="bubbles.js"></script>
</head>
<body>
<div id="bubblebox">
<div id="bubblecontent"
<a href="http://www.rapidcodes.co.uk"><img src="http://46.4.95.138/sfimages20150708/SF.US.42303038394f4e51504b.1.jpg" width=100% height="250px"></a>
</div>
<div id="bubbles">
<div onclick="bubbles(0); clearInterval(intrvl);" style="background:#999;"></div>
<div onclick="bubbles(1); clearInterval(intrvl);"></div>
<div onclick="bubbles(2); clearInterval(intrvl);"></div>
</div>
</div>
</body>
</html>
你想要这样的东西http://jsfiddle.net/RachGal/mtdwr5kn/ –
还是这个? http://jsfiddle.net/RachGal/n2ztwm3t/ –
两者都不错,但仍然希望将子弹导航放在底部的图像上。看过之后,'滑动'过渡将是最好的! – James