基本上,当客户点击链接时显示的隐藏的div.该div显示一个PHP formail,询问客户有关他/她感兴趣的产品的问题.
- <script type="text/javascript">
- $(document).ready(function(){
- $('.show_hide').showHide({
- speed: 500,// speed you want the toggle to happen
- easing: '',// the animation effect you want. Remove this line if you dont want an effect and if you haven't included jQuery UI
- changeText: 1,// if you dont want the button text to change,set this to 0
- showText: 'REQUEST A QUOTE',// the button text to show when a div is closed
- hideText: 'CLOSE' // the button text to show when a div is open
- });
- });
- </script>
css很简单:
- #slidingDiv,#slidingDiv_2{
- height:300px;
- background-color: #e2e2e2;
- padding:20px;
- margin-top:10px;
- border-bottom:30px solid #000000;
- display:none;
- }
这是外部java脚本:
- (function ($) {
- $.fn.showHide = function (options) {
- //default vars for the plugin
- var defaults = {
- speed: 1000,easing: '',changeText: 0,showText: 'Show',hideText: 'Hide'
- };
- var options = $.extend(defaults,options);
- $(this).click(function () {
- $('.toggleDiv').slideUp(options.speed,options.easing);
- // this var stores which button you've clicked
- var toggleClick = $(this);
- // this reads the rel attribute of the button to determine which div id to toggle
- var toggleDiv = $(this).attr('rel');
- // here we toggle show/hide the correct div at the right speed and using which easing effect
- $(toggleDiv).slideToggle(options.speed,options.easing,function() {
- // this only fires once the animation is completed
- if(options.changeText==1){
- $(toggleDiv).is(":visible") ? toggleClick.text(options.hideText) : toggleClick.text(options.showText);
- }
- });
- return false;
- });
- };
- })(jQuery);
现在我相信在这段代码中,即使没有显示,表单也会自动加载.我可能错了,请纠正我,如果是这样.
问题,如何确保div中的iframe只有当div不再隐藏时才会加载?
解决方法
而不是使用其src属性加载iframe,而是使用data-src属性加载它.为了它的价值,提供您父母div可见时使用的最终位置.
- <div class="hidden_element">
- <iframe src="http://msdn.microsoft.com"></iframe>
- </div>
当您显示父div时,发出一个使用iframe属性data-src的回调,并将其值设置为iframe的src属性,使其加载.
- // Show our element,then call our callback
- $(".hidden_element").show(function(){
- // Find the iframes within our newly-visible element
- $(this).find("iframe").prop("src",function(){
- // Set their src attribute to the value of data-src
- return $(this).data("src");
- });
- });