优化colorbox并添加额外的jquery
optimizing colorbox and adding extra jquery
我有两个问题
-
我正在尝试打开一个jQuery颜色框,但它非常慢。原因是我试图从另一个页面获取html内容(我不能使用iframe,因为我只需要这个页面的一部分)。以下代码有效,但点击按钮后需要时间:
$(document).ready(function() { $(".cart-link a").click(function(event) { $(this).colorbox.close(); }); $(".rest-menuitem a").click(function(event) { event.preventDefault(); var result = null; var sURL = $(this).attr("href"); $.colorbox({ html: function() { $.ajax({ url: sURL, type: 'get', dataType: 'html', async: false, success: function(data) { result = data; } }); return $(result).find('.product'); }, width: '650px', height: '10px', onComplete: function() { $(this).colorbox.resize(); } }); }); });
我想知道是否有另一种方法。我不介意颜色框弹出,然后需要时间加载内容。以上版本可以在这个网址找到(http://delivery3.water-7.com/index.php/restaurants/manufacturers/3/Barcelona-Restaurant-&-Winebar/产品)。
-
当用户点击添加到购物车时,我也试图关闭颜色框。但出于某种原因,它没有被触发。当我点击添加到购物车时,
$(".cart-link a").click
不会被触发。有没有一种特殊的方法可以将jquery添加到颜色框内容中?
试试这个:
$(".rest-menuitem a").colorbox({
href: function(){
return $(this).attr('href') + ' .products';
},
width: '650px',
height: '10px',
onComplete: function() {
$(this).colorbox.resize();
}
});
ColorBox使用jQuery的load()方法进行ajax处理,因此您只需要将所需的选择器添加到链接的href中。
对于问题2,你能试试这个吗?
$(document).ready(function() {
$(".cart-link a").live('click',function(event) {
$(this).colorbox.close();
});
});
对于你的问题1.,它会很慢,因为你是从不同的页面获取的。对使用不同的逻辑
For your question no 1
$('selector').colorbox({onLoad: function() { /*Intially load a empty color box with only <div id="contenttoload"></div> (No other html content */
$.ajax({
url :'Your url',
data : {}, //data to send if any
type : "POST" //or get
success:function(data){ /*data means the stuff you want to show in color box which you must return from the other page*/
$('#contenttoload').html(data); //data should be well formatted i mean add your css,classes etc from the server itself */
}
});
}});
相关文章:
- JQuery添加元素需要在我的js之前再次添加JQuery脚本
- 通过jQuery添加ng样式属性,angular不更新
- 使用HTML5 localStorage和jQuery添加到收藏夹/书签
- jQuery添加的文本不显示
- 使用Jquery添加内容
- 如何使用jQuery添加另一个对象的高度作为边距
- JavaScript/jQuery-添加添加和删除类与下一个函数之间的延迟
- 对于每个json结果,使用类jquery添加css
- Jquery添加一个类之后,如何应用css
- 使用jQuery添加和删除属性
- Jquery添加输入字段和日期选择器
- jQuery - 添加删除类 - 设置输入值
- 为什么在这种情况下要向JQuery添加两个链接
- 为图像滑块jquery添加项目符号功能
- 使用jquery添加到表单内部表中的元素不会过帐
- 如何使用jquery添加元素
- 使用Jquery添加XML元素
- 当使用javascript/jquery添加值时,html文本输入表显示不正确
- 将jquery添加到firefox扩展中
- 运行 AJAX 需要什么 - 将 jQuery 添加到页面处理 AJAX 调用