开发者

changing an images src value when the user scrolls jquery

开发者 https://www.devze.com 2023-03-29 02:03 出处:网络
I\'m trying to attach an event handler to the scroll event that changes the value of the image tag\'s src value by returning a random value from an array of src values (titles)

I'm trying to attach an event handler to the scroll event that changes the value of the image tag's src value by returning a random value from an array of src values (titles)

$( function(titlemagic){

var titles =[

//ive omitted the actu开发者_C百科al array contents in consideration of post length

            ];  

var rand = Math.ceil(100*Math.random())

$('#id').attr('src', function(){ return titles[(rand)] }).scroll();

});


Try this

$(document).scroll(function(){
  var rand = Math.ceil(100*Math.random())
  $('#id').attr('src', function(){ return titles[(rand)] }).scroll();
});
0

精彩评论

暂无评论...
验证码 换一张
取 消