wordpress - slideToggle, fadeIn, fadeOut animation shifts up during animation -


i'm creating simple "read more/read less" button wordpress site when pressed reveals hidden content using slidetoggle. it's in form of wordpress plugin. buttons fadein , fadeout. , i'm using php/html display page.

everything working great except 1 little hiccup. reason, when read more button clicked , animation starts, content div (or p tag - can't tell sure) starts few pixels down , shifts after finishes animation. , vice versa, when read less button clicked, animation same thing.

i've looked through php , css , can't find anything. i've inspected elements , removed css way it's not helping.

i've included code , short video show mean.

here link video: https://youtu.be/3lnmapglypi

javascript

jquery('.wpsm-content').addclass('wpsm-content-hide'); jquery('.wpsm-show, .wpsm-hide').removeclass('wpsm-content-hide'); jquery('.wpsm-show').on('click', function (e) {     "use strict";     var currentcontent = jquery(this);     function complete() {         jquery(currentcontent).next('.wpsm-content').slidetoggle(800);     }     jquery(this).fadeout(200, complete);     e.preventdefault(); }); jquery('.wpsm-hide').on('click', function (e) {     "use strict";     var wpsm = jquery(this).parent('.wpsm-content');     function complete() {         wpsm.prev('.wpsm-show').fadein(200);    // read more     }     wpsm.slidetoggle(1250, complete);     e.preventdefault(); }); 

css

.wpsm-show a, .wpsm-show:active, .wpsm-show:visited {    cursor: pointer;    text-decoration: none; } .wpsm-show:hover {    cursor: pointer;    text-decoration: underline; } .wpsm-hide a, .wpsm-hide:active, .wpsm-hide:visited {    cursor: pointer;    text-decoration: none; } .wpsm-hide:hover {    cursor: pointer;    text-decoration: underline; } .wpsm-content-hide {   display: none; } 

php/html

add_shortcode( 'show_more', 'wpsm'); function wpsm( $attr, $smcontent ) {   if (!isset($attr['color'])) $attr['color'] = '#cc0000';   if (!isset($attr['list'])) $attr['list'] = '';   if (!isset($attr['more'])) $attr['more'] = 'show more';   if (!isset($attr['less'])) $attr['less'] = 'show less';   $wpsm_string  = '<div class="show_more">';   $wpsm_string .= '<p class="wpsm-show" style="color: ' . $attr['color'] . ' ">';    $wpsm_string .= $attr['list']. ' '  . $attr['more'];   $wpsm_string .= '</p><div class="wpsm-content">';   $wpsm_string .= $smcontent;   $wpsm_string .= ' <p class="wpsm-hide" style="color: ' . $attr['color'] . ' ">';    $wpsm_string .= $attr['list']. ' '  . $attr['less'];   $wpsm_string .= '</p>';   $wpsm_string .= '</div></div>';   return $wpsm_string; }  add_action( 'wp_enqueue_scripts', 'sm_scripts'); function sm_scripts (){   $plugin_url = plugins_url( '/', __file__ );   wp_enqueue_style (     'sm-style',     $plugin_url . 'wpsm-style.css'   );   wp_enqueue_script (     'sm-script',     $plugin_url . 'wpsm-script-mine.js',     array( 'jquery' ),     '1.0.1',     true   ); }  add_action('wp_footer', 'sm_scripts'); ?> 


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -