小编Boe*_*oel的帖子

getBoundingClientRect().left 返回错误值吗?

我想在 li 元素开始的地方放置一个 div“.indicator”,例如,如果我想相对于第二个 li 定位 div,我会这样做:

indicator.style.left = li[1].getBoundingClientRect().left+"px";
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

indicator.style.left = li[1].getBoundingClientRect().left+"px";
Run Code Online (Sandbox Code Playgroud)
var li = document.querySelectorAll(".ulcontainer > li");

var indicator = document.querySelector(".indicator");

indicator.style.left = li[1].getBoundingClientRect().left+"px";
Run Code Online (Sandbox Code Playgroud)
html {
  box-sizing: border-box;
}
*, *:before, *:after {
  box-sizing: inherit;
}
.ulcontainer {
    white-space: nowrap;
    padding: 0;
    position: relative;
}
.ulcontainer li {
    list-style: none;
    display: inline-block;
    border: 1px solid;
    padding: 0 20px;
}

.indicator {
    background-color: red;
    display: inline-block;
    position: relative;
}
Run Code Online (Sandbox Code Playgroud)

问题是 div getBoundingClientRect().left 没有为 li 元素返回正确的值。如果您运行该示例,您将看到“.indicator”不在当前 li 的开头。

为什么 …

javascript css

5
推荐指数
1
解决办法
6349
查看次数

如何通过元素内的文本正确绘制图标?

我已经使用一种技术检查了很多按钮,其中它们的图标通过“before”伪元素由文本定义,如下所示:

element:before {
    content: "\e604";
}
Run Code Online (Sandbox Code Playgroud)

该代码应该画一颗星星。

我将其添加到我的代码中,但未绘制图标。

.button {
    text-align: center;
    margin-bottom: 16px;
    margin: 0;
    padding: 0;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.23);
    border-radius: 50%;
    transition: all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms;
    display: inline-block;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.16);
    background-color: #00bcd4;
    position: relative;
    height: 56px;
    width: 56px;
    padding: 0;
    overflow: hidden;
    transform: translate3d(0, 0, 0);
}
.button:before {
    content:"\e604";
}
Run Code Online (Sandbox Code Playgroud)

http://jsfiddle.net/egeszqw6/

我该怎么做才能使图标出现?

提前致谢!

html css pseudo-element

3
推荐指数
1
解决办法
1488
查看次数

当根视图是 ScrollView 时,如何正确地使 ConstraintLayout 中的视图占据可见区域的百分比高度

我有这样的视图层次结构

ScrollView
        ConstraintLayout
            ImageView

            LinearLayout
                TextView
                TextView
                TextView
                ...
Run Code Online (Sandbox Code Playgroud)

我想要实现的是 ImageView 在垂直方向上占据了可见屏幕的 65%...的可见区域。

为了得到这样的东西,最好的方法是什么?

在此处输入图片说明

源代码:

<ScrollView
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:fillViewport="true"
  tools:context=".MainActivity">

  <android.support.constraint.ConstraintLayout
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
      android:id="@+id/header"
      android:layout_width="match_parent"
      android:layout_height="0dp"
      android:scaleType="centerCrop"
      android:src="@drawable/rain"
      app:layout_constraintHeight_percent=".65"
      app:layout_constraintLeft_toLeftOf="parent"
      app:layout_constraintRight_toRightOf="parent"
      app:layout_constraintTop_toTopOf="parent"/>

    <LinearLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:orientation="vertical"
      app:layout_constraintLeft_toLeftOf="parent"
      app:layout_constraintRight_toRightOf="parent"
      app:layout_constraintTop_toBottomOf="@id/header">

      <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="AAAAAA"
        android:textSize="50dp"/>

      <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="BBBB"
        android:textSize="50dp"/>

      <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="CCCCC"
        android:textSize="50dp"/>

      <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="DDDDD"
        android:textSize="50dp"/>



    </LinearLayout>
  </android.support.constraint.ConstraintLayout>

</ScrollView>
Run Code Online (Sandbox Code Playgroud)

提前致谢

android android-layout android-scrollview android-coordinatorlayout

3
推荐指数
1
解决办法
641
查看次数

如何在CSS中设置一个百分比的颜色?

我有一些GUI指南,其中指定了这些颜色:

text-color: #000 87%
background-color of the container: #000 20%
Run Code Online (Sandbox Code Playgroud)

如何在CSS中应用这些要求?

我看过这篇文章:https: //stackoverflow.com/a/12021283

但它没有帮助我.

提前致谢!

html css

2
推荐指数
1
解决办法
8979
查看次数

MongoDB - 如何为 Mongoose 中的字段定义多种数据类型?

这是我的 JSON:

{
    "title": "This an item",
    "date":1000123123,
    "data": [
        {
            "type": "html",
            "content": "<h1>Hi there, this is a H1</h1>"
        },
        {

            "type":"img",
            "content": [
                {
                    "title": "Image 1",
                    "url": "www.google.com/1.jpg",
                    "description":"This is the first image"
                }
            ]
        },
        {
            "type": "map",
            "content": [
                {
                    "lat":323434555,
                    "lng":4444343434,
                    "description":"this is just a place"
                }
            ]

        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

如您所见,“数据”字段存储了一个对象数组,其中“内容”字段是可变的。

我应该如何在猫鼬中建模?

这就是我定义架构的方式:

module.exports = mongoose.model('TestObject', new Schema({
    title: String,
    date: Date,
    data: [
        {
            type: String,
            content: Object
        }
    ]
}));
Run Code Online (Sandbox Code Playgroud)

这是“数据”字段的响应: …

mongoose mongodb

2
推荐指数
1
解决办法
5360
查看次数

如何选择两个h2之间的所有元素

我正在使用 jQuery。我有以下 html 片段:

   <h1>Main Title</h1>
    <h2>One header</h2>
        <p>some text</p>
        <p>more text</p>
        <ul><li>a list</li></ul>
    <h2>Another header</h2>
        <a href="######">one link</a>
        <h3>ddd</h3>
        <p>eee</p>

    <h2>Header 3<h2>
    <p>This is a Paragraph</p>
Run Code Online (Sandbox Code Playgroud)

我需要获取每个 h2 元素之间的内容,以便执行以下操作:

First Section text

some text
more text

Second section text

one link
ddd
eee

Third section text
This is a Paragraph
Run Code Online (Sandbox Code Playgroud)

我读过这个资源:http : //www.tutorialspoint.com/jquery/jquery-selectors.htm

但仍然无法弄清楚如何做我需要的。

提前致谢!

html javascript jquery

1
推荐指数
1
解决办法
1085
查看次数

如何使正则表达式替换json文件中的键的值

我想制作一个正则表达式,以便可以对具有许多对象的json文件执行“搜索/替换”。每个对象都有一个包含URL的名为“ resource”的键。

看下面的例子:

"resource":"http://www.img/qwer/123/image.jpg"

"resource":"io.nl.info/221/elephant.gif"

"resource":"simgur.com/icon.png"
Run Code Online (Sandbox Code Playgroud)

我想做一个正则表达式,用这样的字符串替换整个url:img / filename.format

这样,结果将是:

"resource":"img/image.jpg"

"resource":"img/elephant.gif"

"resource":"img/icon.png"
Run Code Online (Sandbox Code Playgroud)

我只是从正则表达式开始,我完全迷失了。我当时想一个有效的主意是写一些以这种“资源”模式开头的东西:”

并以最后五个字符结尾。但我什至不知道如何尝试。

我该如何写正则表达式?

提前致谢!

regex

1
推荐指数
2
解决办法
3869
查看次数

如何避免这个"'元组'对象在我的自定义用户模块中没有属性'photo'"错误?

我正在尝试存储有关使用facebook登录到我的网站的用户的其他信息,因此我创建了一个UserProfile模型.

这是我定义UserProfile的方式:

models.py

from django.contrib.auth.models import User
from django.db.models.signals import post_save

class UserProfile(models.Model):
    user = models.OneToOneField(User)
    photo = models.TextField()

    def create_user_profile(sender, instance, created, **kwargs):
        if created:
            UserProfile.objects.create(user=instance)

    post_save.connect(create_user_profile, sender=User)
Run Code Online (Sandbox Code Playgroud)

settings.py

AUTH_PROFILE_MODULE = 'blog.UserProfile'
Run Code Online (Sandbox Code Playgroud)

而且,由于我使用python-social-auth进行身份验证,我正在实现一个自定义管道,用于在UserProfile中存储用户的图像URL.

from blog.models import UserProfile

def get_profile_picture(
    strategy,
    user,
    response,
    details,
    is_new=False,
    *args,
    **kwargs
    ):
    img_url = 'http://graph.facebook.com/%s/picture?type=large' \
        % response['id']
    profile = UserProfile.objects.get_or_create(user = user)
    profile.photo = img_url
    profile.save()
Run Code Online (Sandbox Code Playgroud)

但是我得到了以下错误:'tuple'对象没有属性'photo'

我知道UserProfile具有属性"photo",因为这是该表的定义:

table|blog_userprofile|blog_userprofile|122|CREATE TABLE "blog_userprofile" (
    "id" integer NOT NULL PRIMARY KEY,
    "user_id" integer NOT NULL UNIQUE …
Run Code Online (Sandbox Code Playgroud)

python django python-social-auth

1
推荐指数
1
解决办法
568
查看次数

如何在不知道Javascript中的文件扩展名的情况下设置img src?

我有一个空的img标签:

<img src="">
Run Code Online (Sandbox Code Playgroud)

然后src应该用Javascript设置,但我只知道图像的名称,而不是扩展名.

这不起作用:

document.querySelector("img").src = "img/image1";
Run Code Online (Sandbox Code Playgroud)

所以我想知道是否有办法设置src而不指定扩展名.

提前致谢.

javascript

0
推荐指数
1
解决办法
3703
查看次数