/    Sign up×
Community /Pin to ProfileBookmark

combine functions

I have 2 scripts, first a jquery backstretch slideshow, second enquire.register for a media query to destroy backstretch for all devices smaller than 1024px.
This works fine for the first img, or when I have only 1 bstretch-img respectively, but the following slides are being called again by backstrecth.
Looks like a minor problem, but i’m kind of lost how to combine these two. Help is much appreciated!

[code]
<script>
// Create an array of images that you’d like to use
var images = [“http://pascalgruenenfelder.ch/wp-content/uploads/bg/BGfyo.jpg”,
];

// A little script for preloading all of the images
// It’s not necessary, but generally a good idea
$(images).each(function(){
$(‘<img/>’)[0].src = this;
});

// The index variable will keep track of which image is currently showing
var index = 0;

// Call backstretch for the first time,
// Here was the first backstretch-instance

// Set an interval that increments the index and sets the new image
// Note: The fadeIn speed set above will be inherited
setInterval(function() {
index = (index >= images.length – 1) ? 0 : index + 1;
$.backstretch(images[index], {speed: 2000});
}, 10000);
</script>

<script>
enquire.register(‘screen and (min-width: 1024px)’, {
match: function() {
$.backstretch(images[index], {speed: 1});
},
unmatch: function() {
$.backstretch(‘destroy’);
}
});
</script>
[/code]

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @mistergreen spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...