domUtil.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. export const setDocumentTitle = function (title) {
  2. document.title = title
  3. const ua = navigator.userAgent
  4. // eslint-disable-next-line
  5. const regex = /\bMicroMessenger\/([\d\.]+)/
  6. if (regex.test(ua) && /ip(hone|od|ad)/i.test(ua)) {
  7. const i = document.createElement('iframe')
  8. i.src = '/favicon.ico'
  9. i.style.display = 'none'
  10. i.onload = function () {
  11. setTimeout(function () {
  12. i.remove()
  13. }, 9)
  14. }
  15. document.body.appendChild(i)
  16. }
  17. }
  18. export const domTitle = process.env.VUE_APP_PRO_NAME
  19. // 设置keyframes属性
  20. export const addKeyFrames = function (id,y,dur){
  21. var style = document.createElement('style');
  22. style.type = 'text/css';
  23. var keyFrames = '\
  24. @-webkit-keyframes A_ID {\
  25. 0% {\
  26. -webkit-transform: translate3d(0, 0, 0);\
  27. transform: translate3d(0, 0, 0);\
  28. }\
  29. 100% {\
  30. -webkit-transform: translate3d(0, A_DYNAMIC_VALUE, 0);\
  31. transform: translate3d(0, A_DYNAMIC_VALUE, 0);\
  32. }\
  33. }\
  34. @keyframes A_ID {\
  35. 0% {\
  36. -webkit-transform: translate3d(0, 0, 0);\
  37. transform: translate3d(0, 0, 0);\
  38. }\
  39. 100% {\
  40. -webkit-transform: translate3d(0, A_DYNAMIC_VALUE, 0);\
  41. transform: translate3d(0, A_DYNAMIC_VALUE, 0);\
  42. }\
  43. }\
  44. .A_ID{\
  45. -webkit-animation: A_DURs A_ID linear infinite normal;\
  46. animation: A_DURs A_ID linear infinite normal;\
  47. position: relative;\
  48. }\
  49. .A_ID:hover{\
  50. animation-play-state:paused;\
  51. }';
  52. style.innerHTML = keyFrames.replace(/A_ID/g, id).replace(/A_DYNAMIC_VALUE/g, y).replace(/A_DUR/g,dur);
  53. document.getElementsByTagName('head')[0].appendChild(style);
  54. }