Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <aside id="wrap">
  <article>
    <nav>nav 1</nav>
    <nav>nav 2</nav>
    <nav>nav 3</nav>
    <nav>nav 4</nav>
  </article>
</aside>

<button class="test">test</button>
              
            
!

CSS

              
                * {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

#wrap {
  margin-left: 10%;
  margin-top: 10%;
  width: 200px;
  /**/
  background-color: #ebccd1;
}

article:after {
  content: "";
  display: table;
  clear: both;
  line-height: 0;
  height: 0;
}

nav {
  float: left;
  border: black 1px solid;
  padding: 0 5%;
  width: 200px;
  line-height: 3em;
  /**/
  font-size: 1.5em;
  text-align: center;
}
              
            
!

JS

              
                 $(function() {
   new window["blockGoodsInfo"]("wrap");
 })

 //******************

 function BlockGoodsInfo(id) {
   //---var

   this.id_instance;

   //--init

   this.init = function() {
     this.id_instance = "#" + id;
     goodsname = id;
     $(".test").click(function() {
       autoplay();
     })
   }

   var article
   var originW;
   var tempBox_1, tempW_1;
   //swipe
   var speed = 300;
   var goodsWidth = 200;
   var currentGood = 0;
   var maxGoods = 0;
   var swipeOptions = {
     allowPageScroll: 'none',
     triggerOnTouchEnd: true,
     swipeStatus: swipeStatus,
     threshold: 75,
     triggerOnTouchLeave: true,
     excludedElements: ".noSwipe,.d1"
   };
   //

   this.initinteract = function() {

     //set vars value
     article = $(this.id_instance + " article");
     tempBox_1 = article.children(":first").clone(false);
     //***
     var num = article.children().length;
     maxGoods = num;

     originW = num * goodsWidth;
     article.width(originW);
     //
     //set vars value
     tempW_1 = article.width() + goodsWidth;
     //***

     //set translateX=0
     TweenLite.set(article, {
       x: 0
     });
     //hand to swipe nav
     article.swipe(swipeOptions);
   }

   //---function

   function autoplay() {
     /*
      * after swipe , click test btn will have html layout broken.
      * else it has no issue.
      */

     //first ,expand article width 
     article.width(tempW_1);
     //second ,append a element by cloning before 
     article.append(tempBox_1);
   }

   function swipeStatus(event, phase, direction, distance) {
     if (phase == "move" && (direction == "left" || direction == "right")) {
       var duration = 0;

       if (direction == "left") {
         scrollImages((goodsWidth * currentGood) + distance, duration);
       } else if (direction == "right") {
         scrollImages((goodsWidth * currentGood) - distance, duration);
       }

     } else if (phase == "cancel") {
       scrollImages(goodsWidth * currentGood, speed);
     } else if (phase == "end") {
       if (direction == "right") {
         previousImage();
       } else if (direction == "left") {
         nextImage();
       }
     }
   }

   function previousImage() {
     currentGood = Math.max(currentGood - 1, 0);
     scrollImages(goodsWidth * currentGood, speed);
   }

   function nextImage() {
     currentGood = Math.min(currentGood + 1, maxGoods - 1);
     scrollImages(goodsWidth * currentGood, speed);
   }

   function scrollImages(distance, duration) {
     article.css("transition", "all " + (duration / 1000).toFixed(1) + "s " + "cubic-bezier(0.19, 1, 0.22, 1)");
     var value = (distance < 0 ? "" : "-") + Math.abs(distance).toString();
     //use gasp to set new value
     TweenLite.set(article, {
       x: value
     });
   }

   //--startup

   this.init();
   this.initinteract();
 }

 window.blockGoodsInfo = BlockGoodsInfo;
              
            
!
999px

Console