开发者

How to select image with .jpg

开发者 https://www.devze.com 2023-01-31 21:02 出处:网络
Is there any way I can target images with .jpg? For example, the following code enlarge all the image. However I want to enlarge only .jpg.

Is there any way I can target images with .jpg?

For example, the following code enlarge all the image. However I want to enlarge only .jpg.

/*
 * If a page url contains /art-8 (not cart-8), then do this.
 * Add a link to zoom an image on the first image on a product page  
 */
if (/[开发者_StackOverflow中文版^c]art-8/.test(location.pathname)) {

$("#system #product_cont img").wrapAll("<ul class=\"cont_thumb\">").wrap("<li>");
$(".cont_thumb").after("<div style='clear:both;padding-bottom: 20px;'></div> ");



$("ul.cont_thumb li").hover(function(){
    $(this).css({
        'z-index': '10'
    });
    $(this).find('img').addClass("hover").stop().animate({
        marginTop: '0px',
        marginLeft: '-35px',
        top: '50%',
        left: '50%',
        width: '344px',
        height: '258px',
        padding: '0px'
    }, 200);

}, function(){
    $(this).css({
        'z-index': '0'
    });
    $(this).find('img').removeClass("hover").stop().animate({
        marginTop: '0',
        marginLeft: '0',
        top: '0',
        left: '0',
        width: '80px',
        height: '60px',
        padding: '3px'
    }, 400);
});


Use $=

$('img[src$=".jpg"]')

http://api.jquery.com/attribute-ends-with-selector/


You can use the selector img[href$=.jpg], img[href$=.jpeg].


Replace

$("ul.cont_thumb li").hover(function(){

with

$("ul.cont_thumb li").filter("img[src$='.jpg']").hover(function(){
0

精彩评论

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