2017-11-11 114 views
1

克隆的視差jquery追加到dom後停止工作。 檢查我的例子:https://codepen.io/anon/pen/rYOrEO克隆追加jquery停止效果

HTML:

<div class="container"> 
    <a href="#" class="clone">Clone</a> 
</div> 
<section class="content"> 
    <div class="jumbotron text-center bg-faded my-5" style="background: url('http://lorempixel.com/1200/600/abstract/1') no-repeat center;" data-paroller-factor="0.5"> 
    <h1 class="heading-1 py-5 text-white">Hello Parallax!</h1> 
    </div> 
</section> 

JS:

$(window).paroller(); 
$(function(){ 
    $('.clone').on('click', function() { 
    alert('hi'); 
    $(".jumbotron").clone().appendTo(".content"); 
    }); 
}); 

回答

0

只需使用

$('#grolsh').clone(); // Copies the element structure 

$('#grolsh').clone(true) // Copies both data and events along with the structure 

$('#grolsh').clone(true).off() // Copies both data and events and removes handlers 

Events bound with .on() and removed using .off(); 

Events bound with .bind() and removed using .unbind(); 

//你更新後的代碼可以在此幫助

$(window).paroller(); 
$(function(){ 
    $('.clone').on('click', function() { 
    alert('hi'); 
     $(".jumbotron").clone(true).prependTo(".content"); 
     $(window).paroller(); 
    }); 
}); 

ref

+0

這是不是工作壓力太大,你可以解釋一下我通過我的鏈接添加例如:codepen –