简体   繁体   中英

cloning element in responsive layout using enquire.js

I'm making a responsive navigation that moves part of a navigation in a different spot between mobile and desktop.

I'm using enquire.js for this to register my breakpoints and move things based on page width.

I am cloning the element and appending it to a different part of the page.

The issue i'm having is that when I go between the mobile and desktop views, the element gets cloned each time - so they start to pile up in desktop view.

I'm not that familiar with enquire.js to make it so that the element only clones if it doesn't already exist.

You can check the element length before cloning like,

if( !$('your-element').length ) // if element not exists then clone
{
    // your code to clone the element
}

If you provide some code to test or make a fiddle then it will more clear to us what you tried and what you need.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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