目标Psuedo类“typed :: after”删除元素

时间:2017-11-29 23:43:27

标签: javascript jquery html css

嗨,请帮助我如何在使用js后定位一个特定的元素:.typed ::下面的代码只能在没有::之前或之后的类中定位类,并且光标位于类型

之后

HTML

<span class="typed"></span>

JS

$(function(){
    $(".typed").typed({
        strings: ["the Philippines"],
        // Optionally use an HTML element to grab strings from (must wrap each string in a <p>)
        stringsElement: null,
        // typing speed
        typeSpeed: 40,
        // time before typing starts
        startDelay: 1200,
        // backspacing speed
        backSpeed: 20,
        // time before backspacing
        backDelay: 500,
        // loop
        loop: true,
        // false = infinite
        loopCount: 1,
        // show cursor
        showCursor: false,
        // character for cursor
        cursorChar: "|",
        // attribute to type (null == text)
        attr: null,
        // either html or text
        contentType: 'html',
        // call when done callback function
        callback: function() {
               $(".typed::after").hide();
        },


    });
});

3 个答案:

答案 0 :(得分:1)

您不能,但您可以通过将.typed设置为:after

,将content元素添加到none元素中以删除callback: function() { $(".typed").addClass('finished'); },
.typed.finished:after{content:none;}

{{1}}

答案 1 :(得分:0)

你不能用javascript来定位伪元素,只有css的东西。

你应该做的是在.typed上切换一个隐藏伪元素的类。

答案 2 :(得分:0)

嗨,请检查我用来操作伪类

的示例脚本
<style>
    .typed:after {
        content: 'foo';
    }
    .typed.hidden:after {
        display: none;
    }
</style>
<script>
    $('.typed').addClass('hidden');
</script> 

这是因为:after或:before创建的内容不是DOM的一部分,因此无法选择或修改。

有关详细信息,请参阅此问题jQuery and hiding :after / :before pseudo classes

相关问题