类似Twitter的功能:点击显示隐藏文本

Twitter like feature: click to reveal hidden text

本文关键字:显示 隐藏 文本 Twitter 功能 类似      更新时间:2023-09-26

我试图创建一个链接,一旦你点击它解锁文本。

我想我几乎在那里,但我不确定如何显示隐藏的文字,下面是我到目前为止所拥有的。如果有人能给我指个方向就好了。

<section id="container">
    <p>Click to show content. <a href="#" id="tweetLink">Tweet Me.</a></p>
    <p class="hidden-text">Locked</p>
</section>

JS

(function ($) {
    var win = null;
    $.fn.tweetAction = function (options, callback) {

        options = $.extend({
            url: window.location.href
        }, options);
        return this.click(function (e) {
            if (win) {
                e.preventDefault();
                return;
            }
            var width = 550,
                height = 350,
                top = (window.screen.height - height) / 2,
                left = (window.screen.width - width) / 2;
            var config = [
                'scrollbars=yes', 'resizable=yes', 'toolbar=no', 'location=yes',
                'width=' + width, 'height=' + height, 'left=' + left, 'top=' + top
            ].join(',');
           win = window.open('http://twitter.com/intent/tweet?'+$.param(options),
                    'TweetWindow',config);
            // Checking whether the window is closed every 100 milliseconds.
            (function checkWindow() {
                try {

                    if (!win || win.closed) {
                        throw "Closed!";
                    }
                    else {
                        setTimeout(checkWindow, 100);
                    }
                }
                catch (e) {
                    win = null;
                    callback();
                }
            })();
            e.preventDefault();
        });
    };
})(jQuery);

JS

$(document).ready(function(){
$('#tweetLink').tweetAction({
    text:       'First tweet',
    url:        '#',
    via:        'website'
},function(){

    $('hidden-text')
    {
        // action here
    }
});
});

JS

// to show an element that's hidden, you can use .show() or just remove the class
// option 1:
$(".hidden-text").show();
// option 2:
$(".hidden-text").removeClass("hidden-text");
CSS

.hidden-text {
  display: none;
}

$('#tweetLink').click(function(){ $('.hidden-text').slideToggle(); })

这将显示和隐藏段落交替每次点击链接

如果你只是想显示,使用。show()。或者。slideup(如果你想要一些效果)而不是。slidetoggle

CSS

确保你的hidden -text类有一个display:none CSS属性。而不是隐藏可见性