{"id":488,"date":"2010-11-01T12:28:06","date_gmt":"2010-11-01T12:28:06","guid":{"rendered":"https://www.divydovy.com/2010/11/adding-a-pause-button-to-jcarousel-slight-fix/"},"modified":"2020-01-23T10:30:13","modified_gmt":"2020-01-23T10:30:13","slug":"adding-a-pause-button-to-jcarousel-slight-fix","status":"publish","type":"post","link":"https://www.divydovy.com/2010/11/adding-a-pause-button-to-jcarousel-slight-fix/","title":{"rendered":"Adding a Pause Button to jCarousel (slight fix)"},"content":{"rendered":"<p>I was recently asked by a client to add a pause button to the jCarousel-powered carousel on their site.</p>\n<p>To do this, I used <a title=\"How to add a pause button to jCarousel\" href=\"http://old.nabble.com/Howto:-Adding-a-pause-button-to-jcarousel-td22057133.html\">this post</a> by Jeremy Mikola (thanks Jeremy). Here&#8217;s his code:</p>\n<p><code><br />\n $(document).ready(function(){&nbsp;<br />\n &nbsp; $('#jcarousel').jcarousel({&nbsp;<br />\n &nbsp; &nbsp; vertical: true,&nbsp;<br />\n &nbsp; &nbsp; scroll: 1,&nbsp;<br />\n &nbsp; &nbsp; auto: 5,&nbsp;<br />\n &nbsp; &nbsp; initCallback: function(jc, state) {&nbsp;<br />\n &nbsp; &nbsp; &nbsp; if (state == 'init') {&nbsp;<br />\n &nbsp; &nbsp; &nbsp; &nbsp; // Insert a play/pause button between the prev/next buttons&nbsp;<br />\n &nbsp; &nbsp; &nbsp; &nbsp; $('div.jcarousel-prev-vertical').after('&lt;div class=\"jcarousel-&nbsp;<br />\n toggle-vertical\" style=\"display:block;\"&gt;&lt;/div&gt;');&nbsp;&nbsp;&nbsp;</code></p>\n<p><code></p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; /* Override the internal startAuto() method, which is called&nbsp;<br />\n after&nbsp;<br />\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* animations complete, to prevent next/prev buttons from&nbsp;<br />\n reactivating&nbsp;<br />\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* the timer while in the pause state.&nbsp;<br />\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/&nbsp;<br />\n &nbsp; &nbsp; &nbsp; &nbsp; jc.startAutoOrig = jc.startAuto;&nbsp;<br />\n &nbsp; &nbsp; &nbsp; &nbsp; jc.startAuto = function() {&nbsp;<br />\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (!jc.paused) {&nbsp;<br />\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jc.startAutoOrig();&nbsp;<br />\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp;<br />\n &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp;</p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; jc.pause = function() {&nbsp;<br />\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $('div.jcarousel-toggle-vertical')&nbsp;<br />\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .removeClass('jcarousel-play-vertical')&nbsp;<br />\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addClass('jcarousel-pause-vertical');&nbsp;<br />\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jc.paused = true;&nbsp;<br />\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jc.stopAuto();&nbsp;<br />\n &nbsp; &nbsp; &nbsp; &nbsp; };&nbsp;</p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; jc.play = function() {&nbsp;<br />\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $('div.jcarousel-toggle-vertical')&nbsp;<br />\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .removeClass('jcarousel-pause-vertical')&nbsp;<br />\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addClass('jcarousel-play-vertical');&nbsp;<br />\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jc.paused = false;&nbsp;<br />\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jc.startAuto();&nbsp;<br />\n &nbsp; &nbsp; &nbsp; &nbsp; };&nbsp;</p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; // Click event for playback toggle button, conditionally calls&nbsp;<br />\n play/pause&nbsp;<br />\n &nbsp; &nbsp; &nbsp; &nbsp; $('div.jcarousel-toggle-vertical').click(function(){&nbsp;<br />\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (this.timer === null) {&nbsp;<br />\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jc.play();&nbsp;<br />\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else {&nbsp;<br />\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jc.pause();&nbsp;<br />\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp;<br />\n &nbsp; &nbsp; &nbsp; &nbsp; });&nbsp;<br />\n &nbsp; &nbsp; &nbsp; }&nbsp;</p>\n<p></code></p>\n<p><code>&nbsp; &nbsp; &nbsp; jc.play();&nbsp;<br />\n &nbsp; &nbsp; }&nbsp;<br />\n &nbsp; });&nbsp;<br />\n });<br />\n </code></p>\n<p>However, I had a bit of trouble with it and had to make a change, as follows:</p>\n<p><code><br />\n For some reason, \"this.timer === null\" wasn't working for me.&nbsp;</code></p>\n<p><code></p>\n<p>I replaced that section with:&nbsp;</p>\n<p>jQuery('div.jcarousel-toggle').click(function(){&nbsp;<br />\n &nbsp; &nbsp; &nbsp; &nbsp; if (jc.paused) {&nbsp;<br />\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jc.play();&nbsp;<br />\n &nbsp; &nbsp; &nbsp; &nbsp; } else {&nbsp;<br />\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jc.pause();&nbsp;<br />\n &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp;<br />\n });&nbsp;</p>\n<p>Seemed logical and seems to work...&nbsp;</p>\n<p></code></p>\n<p><code>Hope that helps someone.&nbsp; </code></p>\n<p>I did try to post this as a comment on Nabble, but it&#8217;s still pending, so I&#8217;m posting here for now.</p>\n","protected":false},"excerpt":{"rendered":"<p>I was recently asked by a client to add a pause button to the jCarousel-powered carousel on their site. To do this, I used this post by Jeremy Mikola (thanks Jeremy). Here&#8217;s his code: $(document).ready(function(){&nbsp; &nbsp; $(&#8216;#jcarousel&#8217;).jcarousel({&nbsp; &nbsp; &nbsp; vertical: true,&nbsp; &nbsp; &nbsp; scroll: 1,&nbsp; &nbsp; &nbsp; auto: 5,&nbsp; &nbsp; &nbsp; initCallback: function(jc, state) {&nbsp; &nbsp; &nbsp; &nbsp; if (state == &#8216;init&#8217;) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Insert a play/pause button between the prev/next buttons&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $(&#8216;div.jcarousel-prev-vertical&#8217;).after(&#8216;&lt;div class=&#8221;jcarousel-&nbsp; toggle-vertical&#8221; style=&#8221;display:block;&#8221;&gt;&lt;/div&gt;&#8217;);&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* Override the internal startAuto() method, which is called&nbsp; after&nbsp; &nbsp; &nbsp; [&hellip;]</p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_uag_custom_page_level_css":"","clkt_auto_upload":"0","_clkt_publish_and_upload":false,"_jetpack_memberships_contains_paid_content":false,"activitypub_content_warning":"","activitypub_content_visibility":"","activitypub_max_image_attachments":3,"activitypub_interaction_policy_quote":"","activitypub_status":"","footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"_wordproof_timestamp":false},"categories":[7],"tags":[62,152,190,208],"my_content_publications":[],"class_list":["post-488","type-post","status-publish","format-standard","hentry","category-web","tag-javascript","tag-jcarousel","tag-jquery","tag-pause"],"blocksy_meta":{"styles_descriptor":{"styles":{"desktop":"","tablet":"","mobile":""},"google_fonts":[],"version":6}},"clkt_attachments":{"featured_image":null,"inline_attachments":[],"upload_candidates":[],"max_free_size":102400,"max_allowed_size":104857600},"_clkt_upload_mode":"new_only","clkt_content_hash":"7274634a97dd2dc24279fa0043b606ec596146ff736a5ea82781106afeaedfb5","customFields":{"clkt_auto_upload":"0","activitypub_content_warning":"","activitypub_content_visibility":"","activitypub_max_image_attachments":3,"activitypub_interaction_policy_quote":"","activitypub_status":"","footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"processed_attachments":{"total_attachments":0,"uploaded_to_arweave":0,"kept_original_urls":0,"upload_summary":{"total":0,"uploaded":0,"failed":0,"too_large":0,"reused":0}}},"paymentAddress":"8_-tV4d15kVVq9Gd-Al2MAIC3LqNtJ_KgFol71TzxPw"}