首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Scroll事件不起作用:主线程上的同步XMLHttpRequest已弃用

Scroll事件不起作用:主线程上的同步XMLHttpRequest已弃用
EN

Stack Overflow用户
提问于 2020-01-10 05:24:11
回答 1查看 35关注 0票数 0

JS Fiddle here

因此,我从API中提取小部件,并尝试动态显示它们。在JS文件中,我在line 104上有一个scroll事件,它检测用户何时滚动到窗口底部。当它出现时,我希望它显示我存储在allWidgets数组中的下3个小部件。

在用户滚动之前,我从allWidgets数组中复制前三个小部件,将它们存储在单独的变量中,并将它们附加到页面。这是在line 94上。

当我第一次滚动到页面底部时,它将加载接下来的三个小部件。但当我下一次滚动到底部时,我得到了错误:

[Deprecation] Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check <URL>.

有谁知道我怎么解决这个问题吗?真的很沮丧,我已经尝试了好几天了!

编辑:由于某种原因,JS不会保留我的scss。如果你想要,这是你要的:

代码语言:javascript
复制
@import url('https://fonts.googleapis.com/css?family=Lato:100&display=swap');
@import url('https://fonts.googleapis.com/css?family=Kulim+Park&display=swap');


$dark: #211b13;
$darker: darken($dark, 30%);
$light: lighten($dark, 10%);
$lighter: lighten($dark, 50%);
$accent: #d17c2c;
$light-accent: lighten($accent, 8%);

body {
  font-family: 'Lato', sans-serif;
  font-weight: 200;
  background: #fafafa;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

h1 {
  font-family: 'Lato', sans-serif;
  font-weight: 100;
}

h2 {
  font-family: 'Lato', sans-serif;
  font-weight: 100;
}

p {
    font-size: 1.1em;
    font-weight: 300;
    line-height: 1.7em;
    color: #999;
}

a {
  text-decoration: none;
}

a,
a:hover,
a:focus {
    color: inherit;
    text-decoration: none;
    transition: all 0.3s;
}

li {
  list-style: none;
}

#content {
  background-image: url(../../Images/background-texture-3.png);
}

header {
  display: flex;
  justify-content: flex-start;
  background-image: url(../../Images/Demographic_Image.png);
}

header h1 {
  color: rgb(193, 193, 193);
  font-family: 'Lato', sans-serif;
  font-size: 1.5rem;
  margin: 2em 0 0 .2em;
  padding-bottom: .3em;
  @media (min-width: 768px) {
    font-size: 2.5rem;
    margin: 1.5em 0 0 .2em;
  }
}

// Quick Facts
.quick-background {
  background: linear-gradient(.25turn, #99f0c0, transparent);
}

.quick-facts {
  font-family: 'Kulim Park', sans-serif;
  background: url('../../Images/quick-facts-icn.png');
  background-size: cover;
  max-width: 40%;
  padding: .3em 0;
  animation: 1s ease-in-out 0s 1 quickFactSlide;
}

@keyframes quickFactSlide {
  0% {
    max-width: 40%;
    // border-radius: 0 100% 0 0;
    transform: translateX(-100%);
  }
  50% {
    transform: translateX(50%);
  }
  60% {
    transform: translateX(-10%);
  }
  100% {
    max-width: 40%;
    // border-radius: 0 100% 0 0;
  }
}


.quick-facts h4 {
  margin-bottom: 0;
  margin-left: .5em;
  font-style: italic;
}

.total-num {
  animation: 4s ease-in-out infinite totalNumColor;
}

@keyframes totalNumColor {
  0% {
    color: black;
  }
  50% {
    color: white;
  }
  100% {
    color: black;
  }
}

.total,
.num {
  margin-left: 1em;
}

.total p,
.num p {
  display: inline-block;
  margin-top: 0;
  margin-bottom: 0;
  color: black;
  font-weight: 300;
  font-size: 1rem;
}

.num {
  font-weight: 900 !important;
}

.widget-total-p {
  text-decoration: underline;
}


/*
    DEMO STYLE
*/


.navbar {
    padding: 15px 10px;
    background: #fff;
    border: none;
    border-radius: 0;
    // margin-bottom: 10px;
    box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.1);
}

.navbar-btn {
    box-shadow: none;
    outline: none !important;
    border: none;
}

#navbarSupportedContent {
  display: flex;
  justify-content: center;
}

.btn-info {
  background-color: $dark;
  border: 3px solid $darker;
}

.btn-info:hover {
  background-color: $light;
  border: 3px solid $dark;
}
//
// .btn-info:focus {
//   background-color: $lighter;
//   border: none;
//   outline: none !important;
//   box-shadow: none;
// }

.btn-info:not(:disabled):not(.disabled).active,
.btn-info:not(:disabled):not(.disabled):active,
.show>.btn-info.dropdown-toggle {
  background-color: $lighter;
  border: $light;
}

.line {
    width: 100%;
    height: 1px;
    border-bottom: 1px dashed #ddd;
    margin: 40px 0;
}

/* ---------------------------------------------------
    SIDEBAR STYLE
----------------------------------------------------- */

.wrapper {
    display: flex;
    flex-grow: 1;
    width: 100%;
}

#sidebar {
    width: 250px;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 999;
    background: $dark;
    color: #fff;
    transition: all 0.3s;
}

#sidebar.active {
    margin-left: -250px;
}

#sidebar .sidebar-header {
    padding: 20px;
    background: $dark;
}

#sidebar ul.components {
    padding: 20px 0;
    border-bottom: 1px solid $light;
}

.home-li {
  position: none;
  font-size: 1.2rem;
  padding: .3em .5em;
  margin-bottom: 0;
  background-color: $light;
  transition: all .7s ease-in-out;
}

.home-li:hover {
  background-color: $accent;
}

// .home-li:focus {
//   outline: none !important;
//   box-shadow: none !important;
//   background-color: $lighter;
// }

.product-title {
  font-family: 'Lato', sans-serif;
  font-weight: 100;
  margin: .5em 3.5em .5em .5em;
  padding-bottom: 0.3em;
  border-bottom: 1px solid $light;
}

#sidebar ul p {
    color: #fff;
}

#sidebar ul li a {
    padding: 10px;
    font-size: 1.1em;
    display: block;
}

#sidebar ul li a:hover {
    background: $light;
}

// #sidebar ul li a:focus {
//     background: $light;
//     outline: none;
//     box-shadow: none;
// }

#sidebar ul li.active>a,
a[aria-expanded="true"] {
    color: #fff;
}

a[data-toggle="collapse"] {
    position: relative;
}

#sidebar .widget-link {
  font-size: 1rem;
}

.dropdown-toggle::after {
    display: block;
    position: absolute;
    top: 50%;
    right: 20px;
    transform: translateY(-50%);
}

ul ul a {
    font-size: 0.9em !important;
    padding-left: 30px !important;
    background: $dark;
}

ul.CTAs {
    padding: 20px;
}

ul.CTAs a {
    text-align: center;
    font-size: 0.9em !important;
    display: block;
    border-radius: 5px;
    margin-bottom: 5px;
}

a.download {
    background: #fff;
    color: #7386D5;
}

a.article,
a.article:hover {
    background: $light !important;
    color: #fff !important;
}

#sidebar .CTAs {
  margin: 0 auto;
}

#sidebar .btn-li {
  display: flex;
  justify-content: center;
  margin: 0 auto;
  font-family: 'Lato', sans-serif;
  font-size: 1.2rem;
  background-color: $accent;
  border: 2px solid $light-accent;
  border-radius: 3px;
  width: 90%;
  transition: background-color .75s ease-in-out;
}

#sidebar .btn-li:hover {
  background-color: $light-accent;
}

#sidebar .website-link {
  color: white;
  font-weight: 100;
  transition: background-color .75s ease-in-out;
}

#sidebar .website-link:hover {
  background-color: transparent;
}

#sidebar .website-btn {
  background-color: transparent;
  border: none;
}

#sidebar .logo-li {
  display: flex;
  justify-content: center;
}

#sidebar .logo-img {
  width: 50px;
  height: 50px;
}

/* ---------------------------------------------------
    CONTENT STYLE
----------------------------------------------------- */

#content {
  width: calc(90% - 250px);
  padding: 5px;
  min-height: 100vh;
  transition: all 0.3s;
  position: absolute;
  top: 0;
  right: 0;
  @media (min-width: 768px) {
    width: calc(100% - 250px);
    padding: 15px;
    min-height: 100vh;
    transition: all 0.3s;
    position: absolute;
    top: 0;
    right: 0;
}
}

#content.active {
    width: 100%;
}

.city-state-btn,
.zipcode-btn,
.county-btn,
.time-zone-btn {
  padding-right: 1.5em;
}

.btn-group {
   margin-left: .5em;
}

.city-state-btn::after,
.zipcode-btn::after,
.county-btn::after,
.time-zone-btn::after {
  right: 10px;
}

.filter-list {
  display: flex;
  justify-content: center;
}

.filter-by {
  font-family: 'Open Sans', sans-serif;
  font-style: italic;
  margin-right: 1em;
}

input {
  margin: 0 .5em;
  padding-left: .5em;
  font-family: 'Lato', sans-serif;
  width: 245px;
}

.btn-control {
  font-family: 'Kulim Park', sans-serif;
  font-size: .9rem;
  background-color: #8ee6b5;
  border: 2px solid darken(#8ee6b5, 10%);
  border-radius: 2px;
  padding: .3em .5em;
}

.search-placeholder {
  margin: 0 auto;
}

.placeholder-img {
  display: flex;
  justify-content: center;
}

.placeholder-txt {
  display: flex;
  justify-content: center;
}

/* ---------------------------------------------------
    MEDIAQUERIES
----------------------------------------------------- */

@media (max-width: 768px) {
    #sidebar {
        margin-left: -250px;
    }
    #sidebar.active {
        margin-left: 0;
    }
    #content {
        width: 100%;
    }
    #content.active {
        width: calc(100% - 250px);
    }
    #sidebarCollapse span {
        display: none;
    }
}

/* ---------------------------------------------------
    WIDGETS
----------------------------------------------------- */

.widgets {
  margin-top: 10px;
}

.trivia-widgets,
.in-the-works-widgets {
  @media (min-width: 768px) {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr 1fr;
    grid-template-areas:
      "widget-1 widget-2"
      "widget-3 widget-4"
      "widget-5 widget-6";
  }
  @media (min-width: 1024px) {
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    grid-template-areas:
      "widget-1 widget-2 widget-3"
      "widget-4 widget-5 widget-6"
  }
}

.widget {
  margin-bottom: 4em;
}

.widget-image {
  text-align: center;
}


iframe {
  border: none;
  display: block;
  margin: 0 auto;
  width: 300px;
  height: 350px;
}

body {
  background-color: transparent !important;
}

.weather-iframe,
.puzzle-iframe,
.in-the-works-iframe,
.games-iframe {
  margin-bottom: 1em;
}

.details {
  margin: 0 .5em;
  background-color: rgb(242, 240, 227);
  border-radius: 4px;
}

.details {
  padding: .5em 0 1em 0;
  margin-bottom: 4em;
}

.detail {
  padding: 0 1em;
  font-family: 'Lato', sans-serif;
  font-weight: 800;
  font-style: normal;
}

.span-detail {
  float: right;
  font-family: 'Lato', sans-serif;
  font-weight: 800;
  font-style: italic;
}

.footer-div {
  z-index: 2000;
}

footer {
  // margin: 0 auto;
  height: 20px;
  // max-width: 90%;
  background-color: $dark;
}
EN

回答 1

Stack Overflow用户

发布于 2020-01-10 05:43:48

只有当您是小部件的作者时,您才能更改任何内容。

小部件所在的https://w1.predictinteractive.com/widgets/weather/index.html页面包含一个名为weather.min.js的JS文件。此文件可能包含一个同步XMLHTTPRequest,它将阻塞您的线程,如警告所示。

您最好使用更新的小部件,该小部件不使用同步XMLHTTPRequest来获取数据。或者,如果您觉得可以,使用众多开放天气API中的一个并构建您自己的小部件。

TL;DR除非您可以更改小部件的JS,否则无法修复它。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59672315

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档