我正在尝试根据图像的尺寸禁用jquery插件,因此如果图像是>如果图像低于禁用插件,则500x480启用其他插件。
我尝试的不起作用。请有人帮帮我吗?
插件的原始功能
$(function(){
$('#zoom1').bind('click',function(){
var cloudZoom = $(this).data('CloudZoom');
cloudZoom.closeZoom();
$.fancybox.open(cloudZoom.getGalleryList());//
return false;
});
});
CloudZoom.quickStart();
我尝试了什么,
var img = document.getElementById('#zoom1');
var width = img.naturalWidth;
var height = img.naturalHeight;
$(function(){
$('#zoom1').bind('click',function(){
var cloudZoom = $(this).data('CloudZoom');
cloudZoom.closeZoom();
$.fancybox.open(cloudZoom.getGalleryList());//
return false;
});
});
if(var width > 500 || height > 480) {
CloudZoom.quickStart();//I would like to initiate this.
}
html
<div class="imgwrap">
<div class="sldwrp">
<div class="sldimgwrp">
<?php if($result->num_rows > 0){ if ($row['image_one'] != '') {?>
<img class="cloudzoom appsld" id ="zoom1" src="<?php echo $path.$row['image_one'];?>"
title="Click to view larger image."
data-cloudzoom='
zoomImage:"<?php echo $path.$row['image_one'];?>",
zoomSizeMode: "image",
captionPosition:"top",
maxMagnification:"4"
'><?php }}?>
</div>
<div class="thumbs">
<div class="thumb_img">
<?php if($result->num_rows > 0){ if ($row['image_one'] != '') {?>
<a href="<?php echo $path.$row['image_one'];?>" class="thumb-link">
<img class="cloudzoom-gallery" id="thumbwd" src="<?php echo $path.$row['image_one'];?>"
data-cloudzoom='
useZoom:"#zoom1",
image:"<?php echo $path.$row['image_one'];?>",
zoomImage:"<?php echo $path.$row['image_one'];?>"'>
</a>
<?php }}?>
答案 0 :(得分:0)
你有几个错误。试试这个:
// fisrt mistake : you have to get the image dimensions when the dom element is created
// for this, put it after the $(function(){
$(function(){
var img = document.getElementById('zoom1'); // second mistake here with the #zoom1 instead of just zoom1
var width = img.naturalWidth;
var height = img.naturalHeight;
$('#zoom1').bind('click',function(){
if (width>500 || height>480) { // make your test here
var cloudZoom = $(this).data('CloudZoom');
cloudZoom.closeZoom();
$.fancybox.open(cloudZoom.getGalleryList());
return false;
}
return true;
});
CloudZoom.quickStart(); // leave this alone
});