简体   繁体   English

jQuery通用问题(循环插件)

[英]jQuery General Question (cycle plugin)

Currently this does work except slide.src is undefined because by default slide.src is looking for an image src tag first, but the image src tag is now inside the div properties. 目前,此功能可以正常工作,但未定义slide.src,因为默认情况下,slide.src首先会查找图像src标签,但是图像src标签现在位于div属性中。

So how can i change the javascript + slide.src + to be(or get) the image inside the div properties. 因此,如何更改javascript + slide.src +成为(或获取)div属性中的图像。

View 视图

<div id="properties">
<?php foreach($search_results->result() as $row) :?>
<div id="<?=$row->mls_listing_id?>"><br>
Listing ID : <?=$row->mls_listing_id?><br>
State: <?=$row->sale_price?><br>
State: <?=$row->mls_state_code?><br>
MLS Office: <?=$row->mls_office_name?><br>
Office Number: <?=$row->mls_office_phone?><br>
Photo: **<img src="<?=$row->photo_url?>" width="175" height="137" /**><br>
</div><!--END specific id div -->
<?php endforeach; ?>

</div><!--End Properties DIV -->

javascript javascript

$('#properties')
.before('<ul id="propnav">')
.cycle({ 
    fx: 'scrollHorz', 
    next:'#next',   
    prev:'#prev',
    pager:  '#propnav', 
    delay: -1000 ,
    // callback fn that creates a thumbnail to use as pager anchor 
    pagerAnchorBuilder: function(idx, slide) { 
        return '<li><a href="#">**<img src="' + slide.src + '"** width="50" height="50" /></a></li>'; 
    }
});

To get the image contained in the div slide, you need to use: $(slide).children('img').attr('src') 要获取div幻灯片中包含的图像,您需要使用: $(slide).children('img').attr('src')

Here's the complete code: 这是完整的代码:

$('#properties')
.before('<ul id="propnav">')
.cycle({ 
    fx: 'scrollHorz', 
    next:'#next',       
    prev:'#prev',
    pager:  '#propnav', 
    delay: -1000 ,
    // callback fn that creates a thumbnail to use as pager anchor 
    pagerAnchorBuilder: function(idx, slide) { 
        return '<li><a href="#">**<img src="' + $(slide).children('img').attr('src') + '"** width="50" height="50" /></a></li>'; 
    }
});

Thanks so much José! 非常感谢José! I needed the same thing, but mine was a big worse ;) 我需要同样的东西,但是我的情况更糟;)

$(slide).children('div').children('span').children('a').children('img').attr('src')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM