change image opacity using javascript

后端 未结 7 1879
失恋的感觉
失恋的感觉 2020-12-05 04:11

how can I change image opacity using javascript? I\'m going to create a fading effect using javascript, is there any sample? is there anything like image.opacity that can be

7条回答
  •  甜味超标
    2020-12-05 05:10

    I'm not sure if you can do this in every browser but you can set the css property of the specified img.
    Try to work with jQuery which allows you to make css changes much faster and efficiently.
    in jQuery you will have the options of using .animate(),.fadeTo(),.fadeIn(),.hide("slow"),.show("slow") for example.
    I mean this CSS snippet should do the work for you:

    img
    {
    opacity:0.4;
    filter:alpha(opacity=40); /* For IE8 and earlier */
    }
    

    Also check out this website where everything further is explained:
    http://www.w3schools.com/css/css_image_transparency.asp

提交回复
热议问题