简体   繁体   English

切换时jQuery UI幻灯片切换更改按钮

[英]jQuery UI slide toggle change button on toggle

$(".myButton").click(function () {

    // Set the effect type
    var effect = 'slide';

    // Set the options for the effect type chosen
    var options = { direction: $('left').val() };

    // Set the duration (default: 400 milliseconds)
    var duration = 1000;

    $('#myDiv').toggle(effect, options, duration);
});

I'm wondering how I can toggle the button to show a new button or text copy in it's place when toggled to 'Read Less' 我想知道如何在切换到“少读”时切换按钮以显示新按钮或文本副本

<center>
<button id="button" class="myButton">Read More</button>
</center>

<div id="myDiv">
<p>Cool Read More Content Here. Lorem Ipsom. Cool Read More Content Here. Lorem Ipsom. Cool Read More Content Here. Lorem Ipsom. Cool Read More Content Here. Lorem Ipsom. Cool Read More Content Here. Lorem Ipsom. Cool Read More Content Here. Lorem Ipsom. Cool Read More Content Here. Lorem Ipsom. Cool Read More Content Here. Lorem Ipsom. Cool Read More Content Here. Lorem Ipsom. Cool Read More Content Here. Lorem Ipsom. Cool Read More Content Here. Lorem Ipsom. Cool Read More Content Here. Lorem Ipsom. Cool Read More Content Here. Lorem Ipsom. Cool Read More Content Here. Lorem Ipsom. Cool Read More Content Here. Lorem Ipsom.</p>
</div>
$(".myButton").click(function () {
    var self = $(this);
    // Set the effect type
    var effect = 'slide';

    // Set the options for the effect type chosen
    var options = { direction: $('left').val() };

    // Set the duration (default: 400 milliseconds)
    var duration = 1000;

    $('#myDiv').toggle(effect, options, duration, function() {
        if (self.text() == "Read More") {
            self.text('Read Less');
        } else {
            self.text('Read More');
        }
    });
});

FIDDLE 小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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