Slideshow auto playing blank in then end in Shopify narrative theme - javascript

I wanted autoplay slideshow in narrative theme its work very well although at the end of the autoplay slideshow, it hangs on a blank slide for quite a bit of time before restarting. how can i remove that and make it slide right to the first image instead of displaying blank . Any help would be great. I entered this code into custom.js
var sections = window.theme.sections;
var slideshowAutoExtension = {
init: function() {
this.on('slideshow_desktop_init_done', this._autoplaySlideshow.bind(this));
},
_autoplaySlideshow: setInterval(function() {
var $slide = $('.slideshow__slide--active')
.removeClass('slideshow__slide--active');
var $button = $('.slideshow__button--active')
.removeClass('slideshow__button--active');
var $slides = $('.slideshow__slide');
var currentIndex = ($slides.index($slide) + 1) % $slides.length;
$slides
.eq(currentIndex)
.addClass('slideshow__slide--active');
var $buttons = $('.slideshow__button')
.eq(currentIndex)
.addClass('slideshow__button--active');
}, 5000)
};
'''

Related

Mozilla firefox makes laggy my jquery slideDown animation

I've met this problem nowadays. I have a div which contains li-img (5of them) and when I try to reappear it with the slideDown animation 3/10 its smooth on mozilla and over 11/11 in chrome. The code and computer is the same and the exact problem is that the slidedown is smooth but the images are not slowing appear as the div appear, sometimes are completely invisible and then suddenly appear. Its not a matter of asyc coding cause i even tried to setTimeout(300) between append and animation but append is synchronous. The only plugin in mozilla is ad-block as in my chrome too. (I know that mozilla considered more heavy browser while chrome considered faster but eats more ram). The code is this (i really dont think its code problem)
$(document).ready(function(){
//classes
var $wrapper= $(".wrapper");
var $header=$wrapper.find(".header");
var $center = $wrapper.find(".center");
var $quiz=$center.find(".quiz");
// buttons-li
var $header_li= $header.find("ul li");
//other elements
var $quiz=$wrapper.find(".quiz");
var $rope = $wrapper.find("#rope")
var $popup;
function getQuiz(){
$.get('./php/get_quiz.php',function(data)
{
$quiz.append("<ul>"+data+"</ul>");
//setTimeout(ropeAnimation,100);
ropeAnimation();
toImgsAddPointer();
$rope.unbind('click');
$rope.removeClass('pointer');
});
}
function submitAnswer(){
var id = $(this).attr("id");
$.get('./php/result.php',{'choice':id},function(data){
var $ul= $center.find("ul");
$ul.remove();
$quiz.append("<ul>"+data+"</ul>");
toImgsAddPointer();
});
}
function clickEvent(){
var purple= '#5061FF';
var white = 'white';
var red= 'red';
var black = 'black';
$(this).css('background-color',purple).css('color',white);
$(this).siblings().css('background-color',red).css('color',black);
if(this.id==1){
var div = "<div class='popup'><object data='./pdf/math1.pdf'></object></div";
}else{
var div = "<div class='popup'><object data='./pdf/math2.pdf'></object></div";
}
$wrapper.prepend(div);
$popup=$(".popup");
$popup.on('click',closePopup);
}
function closePopup(){
$popup.remove();
}
function ropeAnimation(){
$rope.animate({"height":'200px'},100);
$quiz.slideDown(500);
$rope.animate({"height":'50px'},700);
}
function toImgsAddPointer(){
var $img = $quiz.find("li img");
$img.addClass("pointer");
$img.on('click',submitAnswer);
}
$header_li.on('click',clickEvent);
$header_li.addClass("pointer");
$rope.addClass("pointer");
$rope.on('click',getQuiz);
});
The animation is in get_quiz() with ropeanimation().

Javascript - New image on refresh for rotating gallery

I have set up a rotating gallery on a homepage using the Javascript code below. The gallery works great, except I would like to have a different image show on refresh. What do I need to change in the code to make this happen? Thank you!
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script>
$.fn.preload = function() {
this.each(function(){
$('<img/>')[0].src = this;
});
}
var images = Array(
"1.jpg",
"2.jpg",
"3.jpg",
"4.jpg",
"5.jpg",
"6.jpg",
"7.jpg",
"8.jpg"
);
$([images[0],images[1],images[2],images[3],images[4]]).preload();
// Usage:
var currimg = 0;
$(document).ready(function(){
function loadimg(){
$('#outerWrapper').animate({ opacity: 1 }, 400,function(){
//finished animating, minifade out and fade new back in
$('#outerWrapper').animate({ opacity: 0.7 }, 100,function(){
currimg++;
if(currimg > images.length-1){
currimg=0;
}
var newimage = images[currimg];
//swap out bg src
$('#outerWrapper').css("background-image", "url("+newimage+")");
//animate fully back in
$('#outerWrapper').animate({ opacity: 1 }, 600,function(){
//set timer for next
setTimeout(loadimg,5000);
});
});
});
}
setTimeout(loadimg,5000);
});
</script>
You can set currimg to a random value from 0 to n, where n is the total number of images in the gallery. Upon refresh, the currently displayed image will be inclined to be different from the one displayed prior to refresh.
currimg = Math.floor(Math.random()*8);

How to add prev and next button in slide show

I just made this program for slide show it is working well but i want to use previous and next buttons in the slide show and i don't have any idea how to do that so i put this here please help for the same
var image1=new Image()
image1.src="slide/23.jpg"
var image2=new Image()
image2.src="slide/7.jpg"
var image3=new Image()
image3.src="slide/4.jpg"
var image4=new Image()
image4.src="slide/5.jpg"
var image5=new Image()
image5.src="slide/6.jpg"
</script>
<img id="myImg"src="slide/2.jpg" name="img" width="1000" height="250"/>
<script>
var step=1
function slideImages(){
if (!document.images)
return
document.images.img.src=eval("image"+step+".src")
if (step<5)
step++
else
step=1
setTimeout("slideImages()",3000)
}
slideImages()
</script>
You probably want to abstract away some code so it can be easily reused in your functions:
// Dealing with the counter:
var step;
var steps = 5;
function increment() {
s = (s + 1) % steps;
}
function decrement() {
s--;
if (s<0) s = steps-1;
}
// Dealing with the slide show:
function show() {
document.images.img.src=eval("image"+step+".src")
}
function next() {
increment();
show();
}
function prev() {
decrement();
show();
}
// Automatic sliding:
window.setInterval(next, 3000);
Also, i would reconsider your approach to storing images:
function createImgBySource(src){
var img = new Image();
img.src = src;
return img;
}
var images = [
createImgBySource('slide/23.jpg'),
createImgBySource('slide/7.jpg'),
createImgBySource('slide/4.jpg'),
createImgBySource('slide/5.jpg'),
createImgBySource('slide/6.jpg')
];
Now you can change the increment and decrement functions to use images.length instead of steps, so you can add more images without having to alter other variables. Also, your show() function should look like this (getting rid of the nasty eval):
function show() {
document.images.img.src = images[step];
}
Try the below code
var ss = new TINY.fader.init("ss", {
id: "slides", // ID of the slideshow list container
position: 0, // index where the slideshow should start
auto: 0, // automatic advance in seconds, set to 0 to disable auto advance
resume: true, // boolean if the slideshow should resume after interruption
navid: "pagination", // ID of the slide nav list
activeClass: "current", // active class for the nav relating to current slide
pauseHover: true, // boolean if the slideshow should pause on slide hover
navEvent: "click", // click or mouseover nav event toggle
duration: .25 // duration of the JavaScript transition in seconds, else the CSS controls the duration, set to 0 to disable fading
});
got from Here also here is a sample Fiddle
I would consider using something like jCarousel.
I think you are best putting all of your images into an array and then looking over it. I am assuming that the image tag with the ID 'myImg' is the one that you want to update, as such you should use document.getElementByID('myImg') and not document.images.img.src=eval("image"+step+".src") -- eval should also be avoided as the performance is poor and it can be dangerous.
Put this as the end of your page:
<script type="text/javascript">
(function(){
var step = 0;
var images = [image1, image2, image3, image4, image5];
var image = document.getElementByID('myImg');
var slideImages = function() {
image.src = images[step].src;
step++;
if (step == images.length){
step == 0;
}
setTimeout("slideImages()", 3000);
};
slideImages()
})();
</script>

How to get JavaScript to rotate through a series if images

I'm having an issues where I cannot get my code to rotate multiple images in a cycle for my image gallery (just a bunch of images i got on google). I can however to get 1 image to cycle through the images but everything iv tried to get it to work with more than one has failed. Any help/ tips would be useful. Im in college for web development and i understand the basics of javascript it just seems when it comes to creating applications i have a bit of trouble.
Here is a link to my code: jsFiddle
$(document).ready(function () {
var img = document.images;
// Holds the image collection
var counter = 0;
var imgArray = [];
imgArray[0] = "http://www.zeroprox.tk/temp/images/img1.png";
imgArray[1] = "http://www.zeroprox.tk/temp/images/img2.jpg";
imgArray[2] = "http://www.zeroprox.tk/temp/images/img3.png";
imgArray[3] = "http://www.zeroprox.tk/temp/images/img4.jpg";
imgArray[4] = "http://www.zeroprox.tk/temp/images/img5.jpg";
imgArray[5] = "http://www.zeroprox.tk/temp/images/img6.png";
imgArray[6] = "http://www.zeroprox.tk/temp/images/img7.jpg";
imgArray[7] = "http://www.zeroprox.tk/temp/images/img8.png";
$("#left-arrow").click(function () {
if (counter < 0) {
counter = imgArray[counter] - 1;
} else {
counter--;
}
img[1].src = imgArray[counter];
});
// Left arrow... Previous
$("#right-arrow").click(function () {
counter = (counter + 1) % imgArray.length;
img[1].src = imgArray[counter];
});
// right arrow... Next
});
JSFiddle
Check this, it should solve your problem ;)
You were replacing every time the same image, now creates a new one and remove another.
Also added div#imagelist to use as a image container and access easier from JavaScript
var newImg = $(document.createElement("img"));
newImg.attr("src",imgArray[counter]);
$("#imagelist img").last().remove();
$("#imagelist").prepend(newImg);

Javascript timed slideshow not working in the least

And it's saddening. Some background, I'm new to Javascript and this is my first application of in life, and since plowing halfway through half a Javascript textbook in two days. It's an external file that's linked to at the end of my HTML. If any more is required, please ask and I'll do my best to provide.
var slide = document.getElementById("slide");
setInterval(slideshow.changeSrc, 5000);
var slideshow = {
changeSrc : function() {
if(slide.src === "./images/s1.png"){
slide.src = "./images/s2.png";
}
else if(slide.src === "./images/s2.png"){
slide.src = "./images/s3.png";
}
else{
slide.src = "./images/s1.png";
}
}
}
slide.addEventListener("load", slideshow.changeSrc, false);
The src property is the result of the browser resolving the URL you give it. Do not use it for comparisons. In addition, only the window and certain elements such as images or scripts have load events. Try this:
Instead, why not just keep track of an index?
(function() {
var id = 0, slide = document.getElementById('slide');
setInterval(function() {
id++;
slide.src = "images/s"+id+".png";
id %= 3;
},5000);
})();
I think this is what you are trying to achive:
var slide = document.getElementById("slide");
var slideshow = {
changeSrc : function() {
setTimeout(function() {
slide.src = 'http://lorempixel.com/100/100';
}, 1000);
}
}
slide.addEventListener("load", slideshow.changeSrc, false);
http://jsfiddle.net/Bs4gM/

Categories

Resources