简体   繁体   English

如何加载leanmodal div内容onclick

[英]How to load leanmodal div contents onclick

My store's collection pages have the quick-view feature where hovering over products images allow you to click 'Quick View' to open a modal dialog window with summary info about the products. 我的商店的收藏页面具有快速查看功能,其中将鼠标悬停在产品图像上,您可以单击“快速查看”以打开模式对话框窗口,其中包含有关产品的摘要信息。 This is done with the leanModal plugin. 这是通过leanModal插件完成的。

See: http://froy.com/collections/beds-mattresses for example. 请参阅: http//froy.com/collections/beds-mattresses Store is powered by Shopify. 商店由Shopify提供支持。

The problem is, when the page initially loads, all the elements within the modal are loaded despite being hidden. 问题是,当页面最初加载时,尽管被隐藏,但模态中的所有元素都被加载。 This unnecessarily slows down the site. 这不必要地减慢了网站的速度。 I'd like to load the contents within the modal only after the user clicks on 'Quick View.' 我想在用户点击“快速查看”后才加载模态中的内容。

<div class="quick_shop"> <!--This is the modal trigger-->
  <div class="quickview-text">Quick View</div>
</div>
<div class="modal">
  <!--All contents of the modal dialog window go in this div-->
</div>

Script: 脚本:

$('.quick_shop').leanModal(); //Calls the function on the modal trigger
(function($){$.fn.extend({leanModal:function(_1)...});})(jQuery); 
//The above line of code is for leanModal. I didn't paste entire thing cause it's long

Any help would be much appreciated! 任何帮助将非常感激! I'm new and learning so this is all very exciting. 我是新人并且学习所以这一切都非常令人兴奋。

The purpose of the modal div is to have a precise view on one specific element. 模态div的目的是对一个特定元素有一个精确的视图。 In your case (on the webpage you provided), the modal is loaded for each element, which breaks the sense of what you're trying to achieve. 在你的情况下(在你提供的网页上),为每个元素加载模态,这打破了你想要实现的目标。

I've never used the leanModal plugin but I guess you could try doing the following: 我从未使用过leanModal插件,但我猜您可以尝试执行以下操作:

When the "Quick view" is pressed, find the closest element with jQuery .closest() method by searching the element with class .quick_shop, THEN leanModal that single element and display it: 当按下“快速视图”时,通过使用类.quick_shop搜索元素,使用jQuery .closest()方法找到最接近的元素,然后使用单个元素的leanModal并显示它:

$(".quickview-text").on("click", function(e){ $(this).closest(".quick_shop").leanModal(); //Then display it with .show() if it's hidden by default });

Once the modal is closed you can delete the element instead of hiding it with the jQuery's remove() method. 关闭模态后,您可以删除元素,而不是使用jQuery的remove()方法隐藏它。

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

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