小编Sch*_*tod的帖子

AngularJS:更好的观察身高变化的方法

我有旧的可变高度导航问题:position: fixes顶部导航和margin-top: $naviHeight下面的内容.当数据异步加载时导航可以改变高度,因此内容的边距必须随之改变.

我希望这是自成一体的.所以没有加载数据的代码,只有在涉及的html-elements /指令中.

目前我在AngularJS 1.2.0中使用这样的计时器:

/*
* Get notified when height changes and change margin-top
 */
.directive( 'emHeightTarget', function(){
    return {
        link: function( scope, elem, attrs ){

            scope.$on( 'heightchange', function( ev, newHeight ){

                elem.attr( 'style', 'margin-top: ' + (58+newHeight) + 'px' );
            } );
        }
    }
})

/*
* Checks this element periodically for height changes
 */
.directive( 'emHeightSource', ['$timeout', function( $timeout ) {

    return {
        link: function( scope, elem, attrs ){

            function __check(){ …
Run Code Online (Sandbox Code Playgroud)

html javascript css angularjs

37
推荐指数
4
解决办法
8万
查看次数

多重继承的替代方案

经过20多年的Java编程,我希望自己有多重继承.但我并非如此,我正在为这个具体问题寻找替代方案.

真正的应用程序是某种ERP,有点复杂,所以我试图将这个问题转化为汽车.这只是到目前为止,但这是我能做的最好的.

让我们从描述汽车可以做什么的界面开始:

public interface Car {

    public String accelerate();
    public String decelerate();

    public String steerLeft();
    public String steerRight();
}
Run Code Online (Sandbox Code Playgroud)

现在我们有一个基本的(但不是抽象的)实现:

public class BasicCar implements Car {

    protected final String name;

    public BasicCar( String name ) {

        this.name = name;
    }

    // In the real word this method is important and does lots of stuff like calculations and caching
    protected String doDrive( String how ) {
        return name + " is " + how + "ing";
    }
    @Override
    public String …
Run Code Online (Sandbox Code Playgroud)

java inheritance design-patterns

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

jQuery自定义值的动画(不是CSS属性)

我想做最奇怪的事情:使用animate进行值更改,这不是css属性而只是变量.

我需要这个,因为我想在用户点击其边框时旋转元素.所以我需要设置角度值的动画,然后在自定义绘图算法中使用它.

我试图使用隐藏DIV的css属性来存储它的角度值并为其设置动画,但它无法正常工作.

有人可以帮我吗?

css variables jquery jquery-animate

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

AngularJS最佳实践REST/CRUD

使用AngularJS通过REST进行CRUD操作的最佳实践是什么?

特别是这里的Angular-Way是什么.通过这个我的意思是使用最少的代码最默认的角度设置来实现这一点.

我知道$ resource和它的默认操作.我不确定如何实现/命名端点和使用哪些控制器.

对于此示例,我想实现一个简单的用户管理系统,用于创建/更新/删除/列出用户.由于我自己实现了Server-Endpoints,因此我可以完全自由地以最友好的角度进行操作.

我喜欢的答案是这样的:

服务器端点:

GET /service/users -> array of users
GET /service/user/new -> return an empty user with default values which has no id
POST /service/user/new -> store a new user and create an id. return the saved user.
POST /service/user/:ID -> save an existing user. Return the saved user
DELETE /service/user/:ID -> delete an existing user
Run Code Online (Sandbox Code Playgroud)

角服务:

.factory( 'User', [ '$resource', function( $resource ){

    return $resource( '/service/user/:userId', { userId: '@id' …
Run Code Online (Sandbox Code Playgroud)

rest crud angularjs

21
推荐指数
2
解决办法
2万
查看次数

在尝试之前lock.lock()

之间有什么区别:

private Lock lock = new ReentrantLock(true);

public void getIn (int direction) throws InterruptedException {

     lock.lock();
     try {
         ...
Run Code Online (Sandbox Code Playgroud)

...

public void getIn (int direction) throws InterruptedException {

      try {
          lock.lock();
          ...
Run Code Online (Sandbox Code Playgroud)

编译顺利,程序也可以工作(我的意思是相同的输出)

我应该把lock.lock(); 在尝试之前或之后?...

谢谢你的帮助

java locking java.util.concurrent

16
推荐指数
4
解决办法
4061
查看次数

如何计算保证金最高百分比?

我知道这应该是直截了当的,但任何人都可以告诉我为什么当a margin-top: 50%应用于孩子时,下面的子盒子会溢出父母的容器.如何计算保证金最高百分比?

.container {  
  background: lightblue; 
  padding: 10px; 
  height: 200px;
}

p { 
  display: block; 
  border:1px solid red;
  margin-top:50%;
}
Run Code Online (Sandbox Code Playgroud)
<div class="container">
<p> Some Cool content</p>
 
</div>
Run Code Online (Sandbox Code Playgroud)

子元素不应该从200px(父级的设置高度)放置50%,即从顶部100px?

html css

12
推荐指数
2
解决办法
8135
查看次数

一些运行/ JIT错误后,Java循环变慢了?

所以我想对一些基本的java功能进行基准测试,以便为这个问题添加一些信息:将方法声明为静态会带来什么好处.

我知道写作基准有时并不容易,但这里发生的事情我无法解释.

请注意,我并没有考虑如何解决这个问题,而是为什么会发生这种情况*

测试类:

public class TestPerformanceOfStaticVsDynamicCalls {

    private static final long RUNS = 1_000_000_000L;

    public static void main( String [] args ){

        new TestPerformanceOfStaticVsDynamicCalls().run();
    }

    private void run(){

        long r=0;
        long start, end;

        for( int loop = 0; loop<10; loop++ ){

            // Benchmark

            start = System.currentTimeMillis();
            for( long i = 0; i < RUNS; i++ ) {
                r += addStatic( 1, i );
            }
            end = System.currentTimeMillis();
            System.out.println( "Static: " + ( end - start ) + …
Run Code Online (Sandbox Code Playgroud)

java performance benchmarking jit

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

什么是包属性以及如何生成它们?

在将一些证书从密钥库转换为openssl/pem时,我第一次注意到证书之前有"Bag Attributes".

看起来像这样:

Bag Attributes
    friendlyName: CN=PositiveSSL CA,O=Comodo CA Limited,L=Salford,ST=Greater Manchester,C=GB
subject=/C=GB/ST=Greater Manchester/L=Salford/O=Comodo CA Limited/CN=PositiveSSL CA
issuer=/C=US/ST=UT/L=Salt Lake City/O=The USERTRUST    Network/OU=http://www.usertrust.com/CN=UTN-USERFirst-Hardware
Run Code Online (Sandbox Code Playgroud)

他们是否提供任何功能?

我注意到我喜欢它们,因为它们使我的链文件(证书的串联)更加清晰.可悲的是,我下载的ca证书没有它们.

那么我该如何生成它们呢?

c ssl openssl pkcs#12

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

android:折叠工具栏在向上滚动时反弹

我有以下布局

<android.support.design.widget.CoordinatorLayout
    android:id="@+id/rootLayout"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:cardview="http://schemas.android.com/apk/res-auto"
    android:background="@color/white"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:fitsSystemWindows="true"
        android:layout_width="match_parent"
        android:layout_height="250dp">

         <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:minHeight="?attr/actionBarSize"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            android:fitsSystemWindows="true">

                <RelativeLayout 
                    xmlns:android="http://schemas.android.com/apk/res/android"
                    android:id="@+id/layout_toolbar"
                    android:layout_width="fill_parent"
                    android:orientation="vertical"
                    app:layout_collapseMode="parallax" 
                    android:layout_height="match_parent">

                        <com.android.volley.toolbox.VolleyImageView 
                            android:id="@+id/image_toolbar"
                            android:layout_width="fill_parent"
                            android:layout_height="match_parent"
                            android:scaleType="centerCrop"/>

                        .... some text views aligned over image...
                </RelativeLayout>

                <android.support.v7.widget.Toolbar
                    android:id="@+id/tool_bar"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
                    app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />


        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>

        <android.support.v7.widget.RecyclerView
        android:id="@+id/list_brands"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

当我在回收站视图中快速向上滚动时,折叠的工具栏无法顺利打开,但会跳出并关闭.我不知道什么是错的.我正在关注这篇文章.

任何帮助将受到高度赞赏.

android material-design android-collapsingtoolbarlayout

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

Css:位置元素相对于它的容器顶部的底部

我有一个div可变高度的元素,我需要通过它bottom相对于容器顶部来定位.

必须在不更改html的情况下完成此操作.

例如

<div id="container">
    <h1>Some Text<br/>more...</h1>
</div>
Run Code Online (Sandbox Code Playgroud)

h1的底部应低于#container顶部100px .

非常感谢

编辑:

所以通过请求我做了(或没有)尝试过:

  • 正在搜索Google,css bottom top position relative但这不是世界上最好的搜索字词...
  • 通常情况下,我会放一个容器,h1并给它一个100px的高度,但后来我需要更改html,我不能
  • 使用bottom: somevalue但是将元素的底部相对于容器的底部定位.
  • 杀了一些吸血鬼

html css position

6
推荐指数
2
解决办法
4180
查看次数