Using jQuery to change image src when browser is resized

前端 未结 4 984
慢半拍i
慢半拍i 2021-01-14 01:45

I have two different sized images, one if for screens smaller than 759px, the other is for screens larger than 759px.

I have managed to get the source of the images

4条回答
  •  耶瑟儿~
    2021-01-14 02:24

    First try this...

    change your follwoing line of code

    $(window).bind("resize", function(){//Adjusts image when browser resized
            imageresize();
        });
    

    to

    // Bind event listener
        $(window).resize(imageresize);
    

    and put alert inside imageresize to see if it works or not...

    In case above do not work out...I believe there is one problem probably..

    in your code you have

    $(document).ready(function() {
    
     $(window).bind("resize", function(){//Adjusts image when browser resized
            imageresize();
        });
    }
    

    So the function for reside inside jquery which may not work well. On top of that try using simple javascript; i had similar problem and solved using plain javascript and jquery did not work in some browsers.

    Sound strange enough to stop you try at it but would work...

提交回复
热议问题