我的JS打字机代码如下:
问题#1:如何添加不删除的字符串?我想使用一组单词“ We are”作为不会删除的句子的开头。正常情况下,.typeStrings将在“ We are”旁边键入:示例www.cantercompanies.com
问题2:如何在固定的“我们是”和.typeStrings文本颜色之间更改字体颜色?
<script>
var app = document.getElementById('typewriter');
var typewriter = new Typewriter(app, {
loop: true,
delay: 40,
});
typewriter.typeString('transportation')
.pauseFor(550)
.deleteAll(1)
.pauseFor(900)
.typeString('auto dealers')
.pauseFor(550)
.deleteAll(1)
.pauseFor(900)
.typeString('realtors')
.pauseFor(550)
.deleteAll(1)
.pauseFor(900)
.start(0)
<script>
答案 0 :(得分:2)
您可以将HTML元素直接添加到public class messagesFragment extends Fragment {
private FirebaseFirestore db = FirebaseFirestore.getInstance();
private String uid = FirebaseAuth.getInstance().getUid();
private CollectionReference messageRef = db.collection("messages");
private View v;
private RecyclerView recyclerView;
private messageAdapter mAdapter;
private String myEmail;
private FloatingActionButton addmsg;
public messagesFragment() {
}
// Creating the fragment view.
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
v = inflater.inflate(R.layout.messages_fragment, container, false);
addmsg = (FloatingActionButton) v.findViewById(R.id.sendmsgfab);
addmsg.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getActivity(), createmessageActivity.class);
startActivity(intent);
}
});
getemail(); // Here the variable myEmail is null.
return v;
}
private void getemail(){
DocumentReference documentReference = db.collection("users").document(uid);
documentReference.get().addOnSuccessListener(new OnSuccessListener<DocumentSnapshot>() {
@Override
public void onSuccess(final DocumentSnapshot documentSnapshot) {
myEmail = documentSnapshot.get("email").toString();
runOnUiThread(new Runnable() {
public void run() {
setupRecycler();
}
});
}
});
}
private void setupRecycler() {
Query query = messageRef.whereEqualTo("receiver", myEmail);
FirestoreRecyclerOptions<message> options = new FirestoreRecyclerOptions.Builder<message>()
.setQuery(query, message.class)
.build();
mAdapter = new messageAdapter(options);
recyclerView = (RecyclerView) v.findViewById(R.id.messagesRecycler);
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
recyclerView.setAdapter(mAdapter);
mAdapter.startListening();
}
@Override
public void onStart() {
super.onStart();
}
@Override
public void onStop() {
super.onStop();
mAdapter.stopListening();
}
}
中。这意味着您可以用跨距将所有文本包裹起来,并添加类名或将样式直接放在typeString()
内。
<span/>
var app = document.getElementById('app');
var typewriter = new Typewriter(app, {
wrapperClassName: 'test',
delay: 50,
loop: true,
});
typewriter
.typeString('<strong>We are: </strong>')
.pauseFor(550)
.typeString('<span style="color:green;">transportation</span>')
.pauseFor(550)
.deleteChars(14)
.pauseFor(900)
.typeString('<span style="color:blue;">auto dealers</span>')
.pauseFor(550)
.deleteChars(12)
.pauseFor(900)
.typeString('<span style="color:purple;">realtors</span>')
.pauseFor(550)
.deleteChars(8)
.pauseFor(900)
.start();
希望这会有所帮助,